//
//  AdAPI.m
//  RainbowFM
//
//  Created by chenli on 14/12/28.
//  Copyright (c) 2014年 RB. All rights reserved.
//

#import "AdAPI.h"
#import "AFAppDotNetAPIClient.h"

@implementation AdAPI




-(void)fetchAdListWithChannel:(NSString *)channel code:(NSString *)code_ userID:(NSString *)userId result:(void (^)(NSArray *, NSString *))res{
    [[AFAppDotNetAPIClient sharedClient] POST:AD_BASE_URL
                                   parameters:@{@"serviceName" : @"ad_list_req",
                                                @"callType" : @"002",
                                                @"params" : @{@"channel" : channel,
                                                              @"code" : code_,
                                                              @"userId" : userId}}
                                      success:^(NSURLSessionDataTask *task, id responseObject) {
                                          if ([responseObject[@"returnCode"] isEqualToString:@"000000"]) {
                                              res(responseObject[@"result"][@"list"],nil);
                                          }
                                          else{
                                              res(nil,responseObject[@"errorMsg"]);
                                          }
                        
                                      } failure:^(NSURLSessionDataTask *task, NSError *error) {
                                          res(nil,@"");
                                      }];
}


-(void)adStatisticsWithBackParam:(NSString *)backParam userID:(NSString *)userId phoneNum:(NSString *)phone result:(void (^)(BOOL, NSString *))res{
    [[AFAppDotNetAPIClient sharedClient] POST:AD_BASE_URL
                                   parameters:@{@"serviceName" : @"ad_syn_req",
                                                @"callType" : @"002",
                                                @"params" : @{@"backParam" : backParam,
                                                              @"userId" : userId,
                                                              @"ucode" : @"",
                                                              @"ip" : @"",
                                                              @"areaCode" : @"",
                                                              @"phoneVer": [[UIDevice currentDevice] model],
                                                              @"phoneSysVer" : [NSString stringWithFormat:@"iOS%@",[[UIDevice currentDevice] systemVersion]],
                                                              @"phoneNum" : phone}}
                                      success:^(NSURLSessionDataTask *task, id responseObject) {
                                          if ([responseObject[@"returnCode"] isEqualToString:@"000000"]) {
//                                              res(responseObject[@"result"][@"list"],nil);
                                          }
                                          else{
//                                              res(nil,responseObject[@"errorMsg"]);
                                          }
                                          
                                      } failure:^(NSURLSessionDataTask *task, NSError *error) {
//                                          res(nil,@"");
                                      }];
}

@end
